const app = getApp();
Page({
  data: {
    NoticeList: {},
    formattedContent: []
  },

  onLoad(options) {
    const { id } = options;
    const pages = getCurrentPages();
    const indexPage = pages[pages.length - 2];
    if (indexPage && indexPage.data.NoticeList) {
      const detail = indexPage.data.NoticeList.find(item => item.id == id);
      if (detail.content) {
        // 更完善的内容格式化
        const formatted = this.formatContent(detail.content);
        this.setData({ 
          NoticeList: detail,
          formattedContent: formatted
        });
      }
    }
  },

  formatContent(content) {
    // 拆分内容并添加格式标识
    const lines = content.split('\n').filter(line => line.trim() !== '');
    return lines.map(line => {
      if (line.match(/^[一二三四五六七八九十]、/)) {
        return { type: 'title', text: line.replace(/　/g, '') };
      } else if (line.match(/^\d+\./)) {
        return { type: 'subtitle', text: line.replace(/ /g, '') };
      } else {
        return { type: 'text', text: line.replace(/　/g, '  ') }; // 替换全角空格为两个半角空格
      }
    });
  },
  
});